function getUrlParams(url) {
	if (url) {
		// 通过 ? 分割获取后面的参数字符串
		let urlStr = url.split('?')[1]
		// 创建空对象存储参数
		let obj = {};
		if (urlStr) {
			// 再通过 & 将每一个参数单独分割出来
			let paramsArr = urlStr.split('&')
			for (let i = 0, len = paramsArr.length; i < len; i++) {
				// 再通过 = 将每一个参数分割为 key:value 的形式
				let arr = paramsArr[i].split('=')
				obj[arr[0]] = arr[1];
			}
			return obj
		}
	}
}
var sitRemind = new Vue({
	el: '#sitRemind',
	data: {
		popupVisible: false,
		pickerValue: '',
		info: {},
		hour: Array(24).fill(1).map((v, k) => k < 10 ? '0'+k:k+''),
		minute: Array(60).fill(1).map((v, k) => k < 10 ? '0'+k:k+''),
		time: [30,60,90,120,150],
		list: [
			{
				lable: '开始时间',
				value: '09:00',
				type: 1
			}, {
				lable: '结束时间',
				value: '18:00',
				type: 2
			}
		],
		slots: [],
		type: getUrlParams(window.location.href)?.type
	},
	mounted() {
		if(this.type == 1){
			this.list.push({
				lable: '久坐时间',
				value: 60,
				type: 3
			})
		}
		if(this.type == 2){
			this.list.push({
				lable: '间隔时间',
				value: 60,
				type: 3
			})
		}
	},
	methods: {
		confirm() {
			this.popupVisible = false;
			if (this.pickerValue) {
				this.list[this.info.type - 1].value = this.pickerValue
			}
		},
		onValuesChange(_, values) {
			if(this.info.type === 3){
				this.pickerValue = values[0]
			}else{
				this.pickerValue = values[0] + ":" +values[1]
			}
		},
		showPicker(info) {
			this.info = info
			this.popupVisible = true;
			switch (info.type) {
				case 1:
				case 2:
					let val = info.value.split(':');
					console.log(val);
					this.slots = [{
						flex: 1,
						values: this.hour,
						defaultIndex: this.hour.map(v => v).indexOf(val[0])
					},{
						flex: 1,
						values: this.minute,
						defaultIndex: this.minute.map(v => v).indexOf(val[1])
					}]
					break;
				case 3:
					this.slots = [{
						flex: 1,
						values: this.time,
						defaultIndex: this.time.map(v => v).indexOf(info.value)
					}]
					break; 
			}
		}
	},
	filters: {
		filterType(num) {
			switch(num*1){
				case 1:
					return '久坐提醒'
				case 2:
					return '喝水提醒'
				case 4:
					return '抬腕亮屏'
				case 5:
					return '勿扰模式'
				default: 
					return ''
			}
		},
		filterTips(num){
			switch(num*1){
				case 1:
					return '持续久坐时间未活动，设备将震动提醒'
				case 2: 
					return '喝水提醒开启后，到间隔时间点，设备将震动'
				case 5:
					return '勿扰模式开启后，除闹钟意外的其他所有提醒设置将不再提醒'
			}
		}
	}
})